package _作业.Synchronized;

public class Tset01 {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        new Thread(ticket,"张三").start();
        new Thread(ticket,"李四").start();
        new Thread(ticket,"王五").start();
    }
}
class Ticket implements Runnable{
    private int total= 100;
    @Override
    public void run() {
        while (true){
            if (total>0){
                String name = Thread.currentThread().getName();
                total--;
                System.out.println(name+"购买了一张票，余票"+total);
            }else {
                System.out.println("票卖完了，下次再来");
                break;
            }
        }
    }
}
